//
//  SimpleRegistView.m
//  HappyBaby
//
//  Created by 华哥 on 15/11/28.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "SimpleRegistView.h"
#import "Define.h"

@implementation SimpleRegistView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        CGFloat width = 275 * kScaleX;
        CGFloat x = (kScreenWidth - width)/2;
        CGFloat height = 30 * kScaleY;
        CGFloat ySpace = height + 40*kScaleY;
        
        // 用户名
        self.userPhone = [[UITextField alloc] initWithFrame:CGRectMake(x, 50 * kScaleY, width - 100*kScaleX, height)];
        self.userPhone.font = [UIFont systemFontOfSize:kScreenWidth/25];
        self.userPhone.delegate = self;
        self.userPhone.placeholder = @"手机";
        self.userPhone.backgroundColor = [UIColor colorWithRed:226/255.0 green:226/255.0 blue:226/255.0 alpha:1];
        [self addSubview:_userPhone];
        UIView *smallView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10*kScaleX, height)];
        self.userPhone.leftView = smallView;
        self.userPhone.leftViewMode = UITextFieldViewModeAlways;
        
        // 验证button
        self.securityCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.securityCodeBtn.frame = CGRectMake(x+_userPhone.width+10*kScaleX, _userPhone.y, 80*kScaleX, height);
        self.securityCodeBtn.backgroundColor = [UIColor colorWithRed:88/255.0 green:137/255.0 blue:236/255.0 alpha:1];
        
        [self.securityCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        self.securityCodeBtn.titleLabel.font = [UIFont systemFontOfSize:kScreenWidth/25];
        [self addSubview:_securityCodeBtn];
        
        // 创建验证码
        self.securityCode = [[UITextField alloc] initWithFrame:CGRectMake(x, _userPhone.x + ySpace, width, height)];
        self.securityCode.backgroundColor = [UIColor colorWithRed:226/255.0 green:226/255.0 blue:226/255.0 alpha:1];
        self.securityCode.placeholder = @"请输入验证码";
        self.securityCode.delegate = self;
        self.securityCode.font = [UIFont systemFontOfSize:kScreenWidth/25];
        UIView *smallView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10*kScaleX, height)];
        self.securityCode.leftView = smallView2;
        self.securityCode.leftViewMode = UITextFieldViewModeAlways;
        [self addSubview:_securityCode];
        
        // 注册button
        self.registButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.registButton setTitle:@"快速注册" forState:UIControlStateNormal];
        self.registButton.frame = CGRectMake(x, _securityCode.y + ySpace, width, height) ;
        self.registButton.backgroundColor = [UIColor colorWithRed:88/255.0 green:137/255.0 blue:236/255.0 alpha:1];
        self.registButton.titleLabel.font = [UIFont systemFontOfSize:kScreenWidth/25];
        [self.registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self addSubview:_registButton];
        
        
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, _registButton.y + 40*kScaleY, 154*kScaleX, 25*kScaleY)];
        label.font = [UIFont systemFontOfSize:kScreenWidth/28];
        label.textColor = [UIColor grayColor];
        label.text = @"点击'快速注册'代表你同意";
        self.userProtocol = label;
        [self addSubview:label];
        
        self.userProtocolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.userProtocolBtn.frame = CGRectMake(x+label.width, label.y, 90*kScaleX, label.height);
        [self.userProtocolBtn setTitleColor:[UIColor colorWithRed:88/255.0 green:137/255.0 blue:236/255.0 alpha:1] forState:UIControlStateNormal];
        self.userProtocolBtn.titleLabel.font = [UIFont systemFontOfSize:kScreenWidth/28];
        [self.userProtocolBtn setTitle:@"用户使用协议" forState:UIControlStateNormal];
        [self addSubview:_userProtocolBtn];
        
        
        
    }
    return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.userPhone resignFirstResponder];
    [self.securityCode resignFirstResponder];
}

@end
